"""
Case Type   : keywords
Case Name   : opengauss关键字成功(非保留)，自定义数据类型名为成功，部分测试点合理报错
Create At   : 2025/1/16
Owner       : @wang-tianjing1
Description :
    1.关键字tmp作为数据类型不带引号
    2.关键字tmp作为数据类型加双引号
    3.关键字tmp作为数据类型加单引号
    4.关键字tmp作为数据类型加反引号
Expect      :
    1.成功
    2.成功
    3.合理报错
    4.合理报错
History     : by wang-tianjing1 2025/1/16 maxvalue修改为非保留关键字
"""
import unittest
from testcase.utils.Logger import Logger
from testcase.utils.Constant import Constant
from testcase.utils.CommonSH import CommonSH

logger = Logger()
commonsh = CommonSH('dbuser')
constant = Constant()

class Hostname(unittest.TestCase):
    def setUp(self):
         logger.info("------------------------ Opengauss_Function_KeyWord_Maxvalue_Case0020 开始执行--------------------------")
        		
    def test_maxvalue_1(self):
        logger.info("------------------------关键字作为目录对象名不带引号--------------------------")
        SqlMdg = commonsh.execut_db_sql('''create directory maxvalue as '/tmp/';
                                                drop directory maxvalue;''')
        logger.info(SqlMdg)
        self.assertIn('CREATE DIRECTORY', SqlMdg)

        logger.info("------------------------关键字作为目录对象名带双引号-成功--------------------------")
        SqlMdg = commonsh.execut_db_sql('create directory \\\"maxvalue\\\" as \'/tmp/\';'
                                      'drop directory \\\"maxvalue\\\"; ')
        logger.info(SqlMdg)
        self.assertIn('CREATE DIRECTORY', SqlMdg)

        logger.info("------------------------关键字作为目录对象名带单引号 - 合理报错--------------------------")
        SqlMdg = commonsh.execut_db_sql('''drop directory if exists 'maxvalue';''')
        logger.info(SqlMdg)
        self.assertIn(constant.SYNTAX_ERROR_MSG, SqlMdg)
        SqlMdg = commonsh.execut_db_sql(''' create directory 'maxvalue' as '/tmp/';''')
        logger.info(SqlMdg)
        self.assertIn(constant.SYNTAX_ERROR_MSG, SqlMdg)

        logger.info("------------------------关键字作为目录对象名带反引号 - 合理报错--------------------------")
        SqlMdg = commonsh.execut_db_sql('''drop directory if exists \`maxvalue\`;''')
        logger.info(SqlMdg)
        self.assertIn(constant.SYNTAX_ERROR_MSG, SqlMdg)
        SqlMdg = commonsh.execut_db_sql('''create directory \`maxvalue\` as '/tmp/';''')
        logger.info(SqlMdg)
        self.assertIn(constant.SYNTAX_ERROR_MSG, SqlMdg)
		
    def tearDown(self):
        logger.info('------------------------ Opengauss_Function_KeyWord_Maxvalue_Case0020 执行结束--------------------------')
